package com.zbkj.admin.controller.brand;

import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.monitor.ZfbMonitorEquipment;
import com.zbkj.common.monitorchannel.GetDeviceModelV3Request;
import com.zbkj.common.monitorchannel.GetMultiMediaAddrV3Request;
import com.zbkj.common.monitorchannel.vo.*;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.monitor.ZfbMonitorEquipmentCondition;
import com.zbkj.common.request.monitor.ZfbMonitorEquipmentRequest;
import com.zbkj.common.request.monitor.ZfbMonitorEquipmentSearchReq;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.monitor.IZfbMonitorEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: MonitorController
 * @Description: TODO
 * @Author: fanbing
 * @Date: 2024/6/30 13:13
 * @Version: V1.0
 **/
@Slf4j
@RestController
@RequestMapping("api/brand/monitor/quipment")
@Api(tags = "监控设备-控制器")
public class BrandMonitorQuipmentController {


    @Autowired
    private IZfbMonitorEquipmentService zfbMonitorEquipmentService;

    @ApiOperation(value = "查询设备列表")
    @PreAuthorize("hasAuthority('brand:montior:equiopment:page:list')")
    @GetMapping(value = "/getMerchantPageList")
    public CommonResult<CommonPage<ZfbMonitorEquipment>> getMerchantPageList(@Validated ZfbMonitorEquipmentRequest searchRequest) {
        PageInfo<ZfbMonitorEquipment> pageInfo = zfbMonitorEquipmentService.getAdminPage(searchRequest);
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "根据各种查询条件，查询设备列表")
    @GetMapping(value = "/getEquipmentListByCondition")
    public CommonResult<CommonPage<ZfbMonitorEquipment>> getEquipmentListByCondition(@Validated ZfbMonitorEquipmentCondition searchRequest) {
        PageInfo<ZfbMonitorEquipment> pageInfo = zfbMonitorEquipmentService.getEquipmentListByCondition(searchRequest);
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }


    @ApiOperation(value = "唤醒设备")
    @GetMapping(value = "/wakeUpEquipment/{license}")
    public CommonResult wakeUpEquipment(@PathVariable String [] license) {
        log.info("#wakeUpEquipment#license=[{}]", license);
        return CommonResult.success(zfbMonitorEquipmentService.wakeUpEquipment(license));
    }


    @ApiOperation(value = "查询设备状态")
    @GetMapping(value = "/getEquipmentStatus/{license}")
    public CommonResult getEquipmentStatus(@PathVariable(value = "license") String license) {
        return CommonResult.success(zfbMonitorEquipmentService.getEquipmentStatus(license));
    }


    @ApiOperation(value = "查询设备流媒体地址") //配合swagger使用
    @PostMapping(value = "/getMediaAddress")
    public CommonResult getMediaAddress(@RequestBody @Validated ZfbMonitorEquipmentSearchReq searchRequest) {
        return CommonResult.success(zfbMonitorEquipmentService.getMediaAddress(searchRequest.getLicense()));
    }


    @ApiOperation(value = "ptz控制设备") //配合swagger使用
    @PostMapping(value = "/ctrlPTZ")
    public CommonResult ctrlPTZ(@RequestBody @Validated CtrlPTZRequestVo ctrlPTZRequestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.ctrlPTZ(ctrlPTZRequestVo));
    }

    @ApiOperation(value = "通过该命令向设备设置时间信息") //配合swagger使用
    @PostMapping(value = "/setTime")
    public CommonResult setTime(@RequestBody @Validated MonitorSetTimeRequestVo setTimeRequestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.setTime(setTimeRequestVo));
    }


    @ApiOperation(value = "通知设备进⾏行行物理理变焦") //配合swagger使用
    @PostMapping(value = "/setAdjustFocalLength")
    public CommonResult<ThirdMonitorResultVo> setAdjustFocalLength(@RequestBody @Validated AdjustFocalLengthRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.setAdjustFocalLength(requestVo));
    }


    @ApiOperation(value = "通知设备⽴立即进⾏行行抓图操作") //配合swagger使用
    @PostMapping(value = "/noticeDeviceUploadPicRequest")
    public CommonResult<ThirdMonitorResultVo> noticeDeviceUploadPicRequest(@RequestBody @Validated NoticeDeviceUploadPicRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.noticeDeviceUploadPicRequest(requestVo));
    }

    @ApiOperation(value = "查询设备云端录像⽇日历") //配合swagger使用
    @PostMapping(value = "/getVideoQueryCalendar")
    public CommonResult<ThirdMonitorResultVo> getVideoQueryCalendar(@RequestBody @Validated VideoQueryCalendarRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getVideoQueryCalendar(requestVo));
    }

    @ApiOperation(value = "查询设备云端录像列列表") //配合swagger使用
    @PostMapping(value = "/getVideoQueryList")
    public CommonResult<ThirdMonitorResultVo<VideoQueryListResultVo>> getVideoQueryList(@RequestBody @Validated VideoQueryListRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getVideoQueryList(requestVo));
    }

    @ApiOperation(value = "查询设备云端录像详情") //配合swagger使用
    @PostMapping(value = "/getVideoQueryDetail")
    public CommonResult<ThirdMonitorResultVo<VideoQueryDetailResultVo>> getVideoQueryDetail(@RequestBody @Validated VideoQueryDetailRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getVideoQueryDetail(requestVo));
    }


    @ApiOperation(value = "查询设备云端图⽚片列列表") //配合swagger使用
    @PostMapping(value = "/getPictureQueryList")
    public CommonResult<ThirdMonitorResultVo<PictureQueryListResultVo>> getPictureQueryList(@RequestBody @Validated VideoQueryListRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getPictureQueryList(requestVo));
    }

    @ApiOperation(value = "查询设备云端录像详情") //配合swagger使用
    @PostMapping(value = "/getPictureQueryDetail")
    public CommonResult<ThirdMonitorResultVo<PictureQueryDetailResultVo>> getPictureQueryDetail(@RequestBody @Validated PictureQueryDetailRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getPictureQueryDetail(requestVo));
    }


    /**
     * 鹤梦云-4.6.2.2.7 查询设备本地图⽚片列列表(须设备在线才可查询)
     *
     * @param requestVo
     * @return
     */
    @ApiOperation(value = "查询设备本地图⽚片列列表(须设备在线才可查询)") //配合swagger使用
    @PostMapping(value = "/getGetLocalPicList")
    public CommonResult<ThirdMonitorResultVo<GetLocalPicListResultVo>> getGetLocalPicList(@RequestBody @Validated VideoQueryListRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getGetLocalPicList(requestVo));
    }


    /**
     * 查询设备本地录像列列表
     * 鹤梦云-4.6.2.3.5 查询设备本地录像列列表
     *
     * @param requestVo
     * @return
     */
    @ApiOperation(value = "查询设备本地录像列列表") //配合swagger使用
    @PostMapping(value = "/getLocalFileList")
    public CommonResult<ThirdMonitorResultVo<GetLocalFileListResultVo>> getLocalFileList(@RequestBody @Validated GetLocalFileListRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getLocalFileList(requestVo));
    }


    /**
     * 根据事件时间查询设备云端图⽚片详情
     * 鹤梦云-4.6.2.2.5 根据事件时间查询设备云端图⽚片详情
     *
     * @param requestVo
     * @return
     */
    @ApiOperation(value = "根据事件时间查询设备云端图⽚片详情") //配合swagger使用
    @PostMapping(value = "/queryDetailByTime")
    public CommonResult<ThirdMonitorResultVo<PictureQueryDetailByTimeResultVo>> getLocalFileList(@RequestBody @Validated QueryDetailByTimeRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.QueryDetailByTime(requestVo));
    }


    /**
     * 4.5.1 根据产品ID进⾏行行订阅数据
     *
     * @param requestVo
     * @return
     */
    @ApiOperation(value = "根据产品ID进⾏行行订阅数据") //配合swagger使用
    @PostMapping(value = "/subscribe")
    public CommonResult<ThirdMonitorResultVo> subscribe(@RequestBody @Validated MonitorSubscribeRequestVo requestVo) {
        return CommonResult.success(zfbMonitorEquipmentService.subscribe(requestVo));
    }


    /**
     * @param licenseList
     * @return
     */
    @ApiOperation(value = "获取设备license") //配合swagger使用
    @PostMapping(value = "/getMonitorLicense")
    public CommonResult<List<ZfbMonitorEquipment>> getMonitor(@RequestBody List<String> licenseList) {
        return CommonResult.success(zfbMonitorEquipmentService.getMonitorLicense(licenseList));
    }


    /**
     * @param setOpenFlagVo
     * @return
     */
    @ApiOperation(value = "4.6.2.6.3 摄像头开关") //配合swagger使用
    @PostMapping(value = "/setOpenFlag")
    public CommonResult setOpenFlag(@RequestBody MonitorSetOpenFlagVo setOpenFlagVo) {
        return CommonResult.success(zfbMonitorEquipmentService.setOpenFlag(setOpenFlagVo));
    }


    /**
     * 4.6.2.3.4 查询设备本地录像⽇日历
     *
     * @param GetLocalFileCalendarVo
     * @return
     */
    @ApiOperation(value = "4.6.2.3.4 查询设备本地录像⽇日历 ") //配合swagger使用
    @PostMapping(value = "/GetLocalFileCalendar")
    public CommonResult getLocalFileCalendar(@RequestBody GetLocalFileCalendarVo GetLocalFileCalendarVo) {
        return CommonResult.success(zfbMonitorEquipmentService.getLocalFileCalendar(GetLocalFileCalendarVo));
    }


    @ApiOperation(value = "获取v3版本的 accessToken ") //配合swagger使用
    @GetMapping(value = "/getV3AccessToken")
    public CommonResult getV3AccessToken() {
        return CommonResult.success(zfbMonitorEquipmentService.getV3AccessToken());
    }

    @ApiOperation(value = "5.5.8.2 获取 TF 录像回放地址标准流地址 ") //配合swagger使用
    @PostMapping(value = "/GetMultiMediaRecordAddr")
    public CommonResult GetMultiMediaRecordAddr(@RequestBody GetMultiMediaRecordAddrV3Request request) {
        return CommonResult.success(zfbMonitorEquipmentService.GetMultiMediaRecordAddr(request, 0));
    }


    @ApiOperation(value = "5.5.3.2 查询 TF 卡录像列表 ") //配合swagger使用
    @PostMapping(value = "/GetLocalFileList")
    public CommonResult GetLocalFileList(@RequestBody GetLocalFileListV3Request request) {
        return CommonResult.success(zfbMonitorEquipmentService.GetLocalFileList(request, 0));
    }


    @ApiOperation(value = "5.5.3.3 查询 TF 卡事件日历") //配合swagger使用
    @PostMapping(value = "/GetLocalEventCalendar")
    public CommonResult GetLocalEventCalendar(@RequestBody GetLocalEventCalendarV3Request request) {
        return CommonResult.success(zfbMonitorEquipmentService.GetLocalEventCalendar(request, 0));
    }

    @ApiOperation(value = "5.2.2 用户账号添加/删除设备") //配合swagger使用
    @PostMapping(value = "/SetDevices")
    public CommonResult SetDevices(@RequestBody SetDevicesV3Request request) {
        return CommonResult.success(zfbMonitorEquipmentService.SetDevices(request, 0));
    }

    @ApiOperation(value = "5.5.1.1 查询设备的业务配置") //配合swagger使用
    @PostMapping(value = "/GetDeviceModel")
    public CommonResult GetDeviceModel(@RequestBody GetDeviceModelV3Request request) {
        return CommonResult.success(zfbMonitorEquipmentService.GetDeviceModel(request, 0));
    }

    /**
     * 5.5.8.1 获取直播播放地址
     * 功能说明：
     * 1、获取设备流媒体直播地址；
     * 2、请求路径 url: /GMModule/V3/Media/GetMultiMediaAddr；
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "5.5.8.1 获取直播播放地址") //配合swagger使用
    @PostMapping(value = "/GetMultiMediaAddr")
    public CommonResult GetMultiMediaAddr(@RequestBody GetMultiMediaAddrV3Request request) {
        return CommonResult.success(zfbMonitorEquipmentService.GetMultiMediaAddr(request, 0));
    }


    /**
     * 5.5.4.7 摄像机开关
     * 功能说明：
     * 1、关闭摄像机后，停止所有录制，同时app默认不可以观看，同时镜头转向隐私位；
     * 2、请求URL；/GMModule/V3/Device/SetOpenFlag
     *
     * @param requestVo
     * @return
     */
    @ApiOperation(value = "5.5.4.7 摄像机开关") //配合swagger使用
    @PostMapping(value = "/v3SetOpenFlag")
    public CommonResult v3SetOpenFlag(@RequestBody MonitorSetOpenFlagVo requestVo, Integer equipmentType){
        return CommonResult.success(zfbMonitorEquipmentService.v3SetOpenFlag(requestVo, 0));
    }
}
